<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/base}">
<head>
    <title>故障录入 - 维修故障排查系统</title>
</head>
<body>
    <div layout:fragment="content">
        <div class="row">
            <div class="col-12">
                <h1 class="mb-4">故障录入</h1>
                
                <div class="card">
                    <div class="card-header">
                        <h5 class="mb-0">新建故障记录</h5>
                    </div>
                    <div class="card-body">
                        <form th:action="@{/faults/save}" th:object="${fault}" method="post">
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label for="deviceName" class="form-label">设备名称 <span class="text-danger">*</span></label>
                                    <input type="text" class="form-control" id="deviceName" 
                                           th:field="*{deviceName}" required>
                                </div>
                                
                                <div class="col-md-6 mb-3">
                                    <label for="priority" class="form-label">优先级</label>
                                    <select class="form-select" id="priority" th:field="*{priority}">
                                        <option value="">请选择</option>
                                        <option value="LOW">低</option>
                                        <option value="MEDIUM">中</option>
                                        <option value="HIGH">高</option>
                                        <option value="URGENT">紧急</option>
                                    </select>
                                </div>
                            </div>
                            
                            <div class="mb-3">
                                <label for="faultDescription" class="form-label">故障现象描述 <span class="text-danger">*</span></label>
                                <textarea class="form-control" id="faultDescription" rows="4" 
                                          th:field="*{faultDescription}" required></textarea>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label for="occurrenceTime" class="form-label">发生时间 <span class="text-danger">*</span></label>
                                    <input type="datetime-local" class="form-control" id="occurrenceTime" 
                                           th:field="*{occurrenceTime}" required>
                                </div>
                                
                                <div class="col-md-6 mb-3">
                                    <label for="reportedBy" class="form-label">报告人</label>
                                    <input type="text" class="form-control" id="reportedBy" 
                                           th:field="*{reportedBy}">
                                </div>
                            </div>
                            
                            <div class="mb-3">
                                <label for="status" class="form-label">状态</label>
                                <select class="form-select" id="status" th:field="*{status}">
                                    <option th:each="status : ${T(com.repair.system.entity.FaultRecord.FaultStatus).values()}"
                                            th:value="${status}" th:text="${status}"></option>
                                </select>
                            </div>
                            
                            <div class="d-flex justify-content-end">
                                <a th:href="@{/faults}" class="btn btn-secondary me-2">取消</a>
                                <button type="submit" class="btn btn-primary">提交</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div layout:fragment="scripts">
        <script>
            // 设置默认发生时间为当前时间
            document.addEventListener('DOMContentLoaded', function() {
                const now = new Date();
                now.setMinutes(now.getMinutes() - now.getTimezoneOffset());
                document.getElementById('occurrenceTime').value = now.toISOString().slice(0, 16);
            });
        </script>
    </div>
</body>
</html>
